// =============================================================================
//  STATS - Statistical Analysis Tools, v.0.01
//  Copyright (C) 2012  Marco Vettigli
// -----------------------------------------------------------------------------
//
// This program  is free software:  you can  redistribute it and/or  modify it
// under the terms of the  GNU General Public License as published by the Free
// Software Foundation,  either version 3 of the License,  or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY;  without even  the  implied  warranty  of  MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License  for
// more details.
//
// You  should  have received a copy of the  GNU General Public License  along
// with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// == module ===================================================================
//
// DIALOGINSERTROWS.CPP
// The class defines a graphical user interface for multiple row insertion.
//
// Author: Marco Vettigli
//
// TODO: write DialogInsertRows module description
//
// == implementation ===========================================================
//
// TODO: write DialogInsertRows implementation description
//
// =============================================================================

// == include directives =======================================================

#include "dialoginsertrows.h"
#include "ui_dialoginsertrows.h"

// == constructors and destructors =============================================

DialogInsertRows::DialogInsertRows(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogInsertRows)
{
    ui->setupUi(this);
}

DialogInsertRows::~DialogInsertRows()
{
    delete ui;
}

// == getters ==================================================================

int DialogInsertRows::getRowNumber() const
{
    return ui->spinNumber->value();
}

DialogInsertRows::Position DialogInsertRows::getInsertionPosition() const
{
    if (ui->checkAfterSel->isChecked())
        return DialogInsertRows::AfterSelected;
    if (ui->checkBeforeSel->isChecked())
        return DialogInsertRows::BeforeSelected;
    if (ui->checkBegin->isChecked())
        return DialogInsertRows::Begin;
    if (ui->checkEnd->isChecked())
        return DialogInsertRows::End;
    return DialogInsertRows::BeforeSelected;
}

// == setters ==================================================================

bool DialogInsertRows::setRowNumber(int number)
{
    // check if number is valid
    if (number < 1) return false;
    // update row number and return
    ui->spinNumber->setValue(number);
    return true;
}

bool DialogInsertRows::setInsertionPosition(DialogInsertRows::Position pos)
{
    switch (pos) {
    case DialogInsertRows::AfterSelected:
        ui->checkAfterSel->setChecked(true);
        return true;
    case DialogInsertRows::BeforeSelected:
        ui->checkBeforeSel->setChecked(true);
        return true;
    case DialogInsertRows::Begin:
        ui->checkBegin->setChecked(true);
        return true;
    case DialogInsertRows::End:
        ui->checkBeforeSel->setChecked(true);
        return true;
    default: return false;
    }   
}

// == inspectors ===============================================================

// == accessor function definitions ============================================

// == static variables =========================================================

// == static funtion definitions ===============================================

// == private function definitions =============================================

void DialogInsertRows::on_buttonBox_accepted()
{
    accept();
}

void DialogInsertRows::on_buttonBox_rejected()
{
    reject();
}
